/*
* 堆栈中的代码执行流程
* */

let a = 10;
function foo(b) {
  let a = 2;
  return function(c) {
    console.log(a + b + c)
  }
}

let fn = foo(2);

fn(3);

/*
* 减少判断层级
* 提前return
* else if 更建议 switch case易于维护，但是性能优化不一定更快
* if else 更适合做区间性判断而不是固定值
* */

// function doSomeThing(part, chapter) {
//   let parts = ['123', '321', '3333', '44444'];
//   if (part) {
//     if (parts.includes(part)) {
//       console.log('include parts')
//       if (chapter > 5) {
//         console.log('need vip')
//       }
//     }
//   } else {
//     console.log('confirm part')
//   }
// }

function doSomeThing(part, chapter) {
  let parts = ['123', '321', '3333', '44444'];
  if (!part) {
    console.log('confirm part');
    return
  }
  if (!parts.includes(part)) return;
  console.log('include parts');
  if (chapter > 5) {
    console.log('need vip')
  }
}

doSomeThing('123', 6);